package org.example.线程池;

import java.util.concurrent.*;

public class 自定义拒绝策略 {

    public static void main(String[] args) {
            RejectedExecutionHandler rejectedExecutionHandler = new RejectedExecutionHandler(){
                @Override
                public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
                    if(executor.getQueue().size() > 100){
                        System.out.println("线程池任务数量大于100了，要不要限制什么的");
                    }
                }
            };

            ThreadPoolExecutor s = new ThreadPoolExecutor(2, 4, 60, TimeUnit.SECONDS,
                    new ArrayBlockingQueue<Runnable>(4), Executors.defaultThreadFactory(),
                    rejectedExecutionHandler);
    }
}
